//using IBatisNet.Common.Transaction;

namespace Sedna.Core.Persistence
{
	/// <summary>
	/// this is the main interface to interact with transactions.
	/// developers are encouraged to prefer this interface instead of the 
	/// direct calls to a corresponding NHibernate methods and interfaces,
	/// since that might complicate the consistent transaction management
	/// throughout the Sedna infrastructure
	/// </summary>
	public interface ITxManager
	{
		/// <summary>
		/// crerates a new or joins an existent thread (or whatever) transaction
		/// </summary>
		/// <returns>true if a new transaction is started or false if joined to an existent one</returns>
		bool BeginOrJoinTx();

		/// <summary>
		/// attempts to commit a current transaction.
		/// if no transaction has been open or if a transaction is inactive <see cref="PstStateException"/> is thrown
		/// </summary>
		void CommitTx();

		/// <summary>
		/// attempts to commit a curren transaction
		/// if isMyTx parameter is true.
		/// this is a convenience method that incapsulates an extra if() statement
		/// </summary>
		/// <param name="isMyTx">if true - commits a transaction, otherwise a call is ignored</param>
		void CommitTx(bool isMyTx);

		/// <summary>
		/// attempts to rollback a current transaction (if any)
		/// if no transaction has been created or a transaction is inactive
		/// the method just returns, thus it is safe to call this method several 
		/// times (though not recommended for fear of the program code inclarity)
		/// </summary>
		void RollbackTx();


		/// <summary>
		/// returns current active transaction. 
		/// if a transaction is not active (e.g. has been committed or rolled back)
		/// the property returns null
		/// </summary>
		NHibernate.ITransaction CurrentTx
		{
			get;
		}

	    
	}
}
